﻿using System;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using DBUtility;
namespace OracleDAL.SUBSYSTEM
{
    /// <summary>
	/// 数据访问类SUBSYS_INFO。
	/// </summary>
	public class SUBSYS_INFO
	{
		public SUBSYS_INFO()
		{}
		#region  成员方法

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string SUBSYSTEMID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from SUBSYS_INFO");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,50)};
			parameters[0].Value = SUBSYSTEMID;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(Model.SUBSYSTEM.SUBSYS_INFO model)
		{
            //StringBuilder strSql=new StringBuilder();
            //strSql.Append("insert into SUBSYS_INFO(");
            //strSql.Append("SUBSYSTEMID,SUBSYSTEMNAME,SUBSYSTEMLOGONMETHOD,SUBSYSTEMLOGONURL,SUBSYSTEMCREATEUSERISN,SUBSYSTEMCREATETIME,SUBSYSTEMCHANGETIME,SUBSYSTEMCHANGEUSERISN,SUBSYSTEMSTATE,SUBSYSTEMRUNNINGSTATE,SUBSYSTEMTYPE,SUBSYSTEMUSERMANAGETYPE,SUBSYSTEMREMARK,SUBSYSIMAGE,ISDISPLAY,DIRECTION)");
            //strSql.Append(" values (");
            //strSql.Append(":SUBSYSTEMID,:SUBSYSTEMNAME,:SUBSYSTEMLOGONMETHOD,:SUBSYSTEMLOGONURL,:SUBSYSTEMCREATEUSERISN,:SUBSYSTEMCREATETIME,:SUBSYSTEMCHANGETIME,:SUBSYSTEMCHANGEUSERISN,:SUBSYSTEMSTATE,:SUBSYSTEMRUNNINGSTATE,:SUBSYSTEMTYPE,:SUBSYSTEMUSERMANAGETYPE,:SUBSYSTEMREMARK,:SUBSYSIMAGE,:ISDISPLAY,:DIRECTION)");
            OracleParameter[] parameters = {
					new OracleParameter("p_subsystemid", OracleType.VarChar,25),
					new OracleParameter("p_subsystemname", OracleType.VarChar,100),
					new OracleParameter("p_subsystemlogonmethod", OracleType.VarChar,20),
					new OracleParameter("p_subsystemlogonurl", OracleType.VarChar,400),
					new OracleParameter("p_subsystemcreateuserisn", OracleType.VarChar,25),
					new OracleParameter("p_subsystemcreatetime", OracleType.DateTime),
					new OracleParameter("p_subsystemchangetime", OracleType.DateTime),
					new OracleParameter("p_subsystemchangeuserisn", OracleType.VarChar,25),
					new OracleParameter("p_subsystemstate", OracleType.VarChar,2),
					new OracleParameter("p_subsystemrunningstate", OracleType.VarChar,2),
					new OracleParameter("p_subsystemtype", OracleType.VarChar,50),
					new OracleParameter("p_subsystemusermanagetype", OracleType.VarChar,50),
					new OracleParameter("p_subsystemremark", OracleType.VarChar,500),
					new OracleParameter("p_subsyimage", OracleType.VarChar,100),
					new OracleParameter("p_isdisplay", OracleType.VarChar,2),
					new OracleParameter("p_direction", OracleType.VarChar,5)};
            parameters[0].Value = model.SUBSYSTEMID;
            parameters[1].Value = model.SUBSYSTEMNAME;
            parameters[2].Value = model.SUBSYSTEMLOGONMETHOD;
            parameters[3].Value = model.SUBSYSTEMLOGONURL;
            parameters[4].Value = model.SUBSYSTEMCREATEUSERISN;
            parameters[5].Value = model.SUBSYSTEMCREATETIME;
            parameters[6].Value = model.SUBSYSTEMCHANGETIME;
            parameters[7].Value = model.SUBSYSTEMCHANGEUSERISN;
            parameters[8].Value = model.SUBSYSTEMSTATE;
            parameters[9].Value = model.SUBSYSTEMRUNNINGSTATE;
            parameters[10].Value = model.SUBSYSTEMTYPE;
            parameters[11].Value = model.SUBSYSTEMUSERMANAGETYPE;
            parameters[12].Value = model.SUBSYSTEMREMARK;
            parameters[13].Value = model.SUBSYSIMAGE;
            parameters[14].Value = model.ISDISPLAY;
            parameters[15].Value = model.DIRECTION;

            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[2].Direction = ParameterDirection.Input;
            parameters[3].Direction = ParameterDirection.Input;
            parameters[4].Direction = ParameterDirection.Input;
            parameters[5].Direction = ParameterDirection.Input;
            parameters[6].Direction = ParameterDirection.Input;
            parameters[7].Direction = ParameterDirection.Input;
            parameters[8].Direction = ParameterDirection.Input;
            parameters[9].Direction = ParameterDirection.Input;
            parameters[10].Direction = ParameterDirection.Input;
            parameters[11].Direction = ParameterDirection.Input;
            parameters[12].Direction = ParameterDirection.Input;
            parameters[13].Direction = ParameterDirection.Input;
            parameters[14].Direction = ParameterDirection.Input;
            parameters[15].Direction = ParameterDirection.Input;

            //OracleHelper.ExecuteSql(strSql.ToString(),parameters);
            OracleHelper.RunProcedure("INSERT_SUBSYS_INFO", parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(Model.SUBSYSTEM.SUBSYS_INFO model)
		{
            //StringBuilder strSql = new StringBuilder();
            //strSql.Append("update SUBSYS_INFO set ");
            //strSql.Append("SUBSYSTEMID=:SUBSYSTEMID,");
            //strSql.Append("SUBSYSTEMNAME=:SUBSYSTEMNAME,");
            //strSql.Append("SUBSYSTEMLOGONMETHOD=:SUBSYSTEMLOGONMETHOD,");
            //strSql.Append("SUBSYSTEMLOGONURL=:SUBSYSTEMLOGONURL,");
            //strSql.Append("SUBSYSTEMCREATEUSERISN=:SUBSYSTEMCREATEUSERISN,");
            //strSql.Append("SUBSYSTEMCREATETIME=:SUBSYSTEMCREATETIME,");
            //strSql.Append("SUBSYSTEMCHANGETIME=:SUBSYSTEMCHANGETIME,");
            //strSql.Append("SUBSYSTEMCHANGEUSERISN=:SUBSYSTEMCHANGEUSERISN,");
            //strSql.Append("SUBSYSTEMSTATE=:SUBSYSTEMSTATE,");
            //strSql.Append("SUBSYSTEMRUNNINGSTATE=:SUBSYSTEMRUNNINGSTATE,");
            //strSql.Append("SUBSYSTEMTYPE=:SUBSYSTEMTYPE,");
            //strSql.Append("SUBSYSTEMUSERMANAGETYPE=:SUBSYSTEMUSERMANAGETYPE,");
            //strSql.Append("SUBSYSTEMREMARK=:SUBSYSTEMREMARK,");
            //strSql.Append("SUBSYSIMAGE=:SUBSYSIMAGE,");
            //strSql.Append("ISDISPLAY=:ISDISPLAY,");
            //strSql.Append("DIRECTION=:DIRECTION");
            //strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID ");
            OracleParameter[] parameters = {
					new OracleParameter("p_subsystemid", OracleType.VarChar,25),
					new OracleParameter("p_subsystemname", OracleType.VarChar,100),
					new OracleParameter("p_subsystemlogonmethod", OracleType.VarChar,20),
					new OracleParameter("p_subsystemlogonurl", OracleType.VarChar,400),
					new OracleParameter("p_subsystemcreateuserisn", OracleType.VarChar,25),
					new OracleParameter("p_subsystemcreatetime", OracleType.DateTime),
					new OracleParameter("p_subsystemchangetime", OracleType.DateTime),
					new OracleParameter("p_subsystemchangeuserisn", OracleType.VarChar,25),
					new OracleParameter("p_subsystemstate", OracleType.VarChar,2),
					new OracleParameter("p_subsystemrunningstate", OracleType.VarChar,2),
					new OracleParameter("p_subsystemtype", OracleType.VarChar,50),
					new OracleParameter("p_subsystemusermanagetype", OracleType.VarChar,50),
					new OracleParameter("p_subsystemremark", OracleType.VarChar,500),
					new OracleParameter("p_subsyimage", OracleType.VarChar,100),
					new OracleParameter("p_isdisplay", OracleType.VarChar,2),
					new OracleParameter("p_direction", OracleType.VarChar,5)};
            parameters[0].Value = model.SUBSYSTEMID;
            parameters[1].Value = model.SUBSYSTEMNAME;
            parameters[2].Value = model.SUBSYSTEMLOGONMETHOD;
            parameters[3].Value = model.SUBSYSTEMLOGONURL;
            parameters[4].Value = model.SUBSYSTEMCREATEUSERISN;
            parameters[5].Value = model.SUBSYSTEMCREATETIME;
            parameters[6].Value = model.SUBSYSTEMCHANGETIME;
            parameters[7].Value = model.SUBSYSTEMCHANGEUSERISN;
            parameters[8].Value = model.SUBSYSTEMSTATE;
            parameters[9].Value = model.SUBSYSTEMRUNNINGSTATE;
            parameters[10].Value = model.SUBSYSTEMTYPE;
            parameters[11].Value = model.SUBSYSTEMUSERMANAGETYPE;
            parameters[12].Value = model.SUBSYSTEMREMARK;
            parameters[13].Value = model.SUBSYSIMAGE;
            parameters[14].Value = model.ISDISPLAY;
            parameters[15].Value = model.DIRECTION;

            parameters[0].Direction = ParameterDirection.Input;
            parameters[1].Direction = ParameterDirection.Input;
            parameters[2].Direction = ParameterDirection.Input;
            parameters[3].Direction = ParameterDirection.Input;
            parameters[4].Direction = ParameterDirection.Input;
            parameters[5].Direction = ParameterDirection.Input;
            parameters[6].Direction = ParameterDirection.Input;
            parameters[7].Direction = ParameterDirection.Input;
            parameters[8].Direction = ParameterDirection.Input;
            parameters[9].Direction = ParameterDirection.Input;
            parameters[10].Direction = ParameterDirection.Input;
            parameters[11].Direction = ParameterDirection.Input;
            parameters[12].Direction = ParameterDirection.Input;
            parameters[13].Direction = ParameterDirection.Input;
            parameters[14].Direction = ParameterDirection.Input;
            parameters[15].Direction = ParameterDirection.Input;

			//OracleHelper.ExecuteSql(strSql.ToString(),parameters);
            OracleHelper.RunProcedure("UPDATE_SUBSYS_INFO", parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string SUBSYSTEMID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from SUBSYS_INFO ");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,50)};
			parameters[0].Value = SUBSYSTEMID;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.SUBSYSTEM.SUBSYS_INFO GetModel(string SUBSYSTEMID)
		{
			
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select SUBSYSTEMID,SUBSYSTEMNAME,SUBSYSTEMLOGONMETHOD,SUBSYSTEMLOGONURL,SUBSYSTEMCREATEUSERISN,SUBSYSTEMCREATETIME,SUBSYSTEMCHANGETIME,SUBSYSTEMCHANGEUSERISN,SUBSYSTEMSTATE,SUBSYSTEMRUNNINGSTATE,SUBSYSTEMTYPE,SUBSYSTEMUSERMANAGETYPE,SUBSYSTEMREMARK,SUBSYSIMAGE,ISDISPLAY,DIRECTION from SUBSYS_INFO ");
			strSql.Append(" where SUBSYSTEMID=:SUBSYSTEMID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SUBSYSTEMID", OracleType.VarChar,50)};
			parameters[0].Value = SUBSYSTEMID;

			Model.SUBSYSTEM.SUBSYS_INFO model=new Model.SUBSYSTEM.SUBSYS_INFO();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.SUBSYSTEMID=ds.Tables[0].Rows[0]["SUBSYSTEMID"].ToString();
				model.SUBSYSTEMNAME=ds.Tables[0].Rows[0]["SUBSYSTEMNAME"].ToString();
				model.SUBSYSTEMLOGONMETHOD=ds.Tables[0].Rows[0]["SUBSYSTEMLOGONMETHOD"].ToString();
				model.SUBSYSTEMLOGONURL=ds.Tables[0].Rows[0]["SUBSYSTEMLOGONURL"].ToString();
				model.SUBSYSTEMCREATEUSERISN=ds.Tables[0].Rows[0]["SUBSYSTEMCREATEUSERISN"].ToString();
				if(ds.Tables[0].Rows[0]["SUBSYSTEMCREATETIME"].ToString()!="")
				{
					model.SUBSYSTEMCREATETIME=DateTime.Parse(ds.Tables[0].Rows[0]["SUBSYSTEMCREATETIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["SUBSYSTEMCHANGETIME"].ToString()!="")
				{
					model.SUBSYSTEMCHANGETIME=DateTime.Parse(ds.Tables[0].Rows[0]["SUBSYSTEMCHANGETIME"].ToString());
				}
				model.SUBSYSTEMCHANGEUSERISN=ds.Tables[0].Rows[0]["SUBSYSTEMCHANGEUSERISN"].ToString();
				model.SUBSYSTEMSTATE=ds.Tables[0].Rows[0]["SUBSYSTEMSTATE"].ToString();
				model.SUBSYSTEMRUNNINGSTATE=ds.Tables[0].Rows[0]["SUBSYSTEMRUNNINGSTATE"].ToString();
				model.SUBSYSTEMTYPE=ds.Tables[0].Rows[0]["SUBSYSTEMTYPE"].ToString();
				model.SUBSYSTEMUSERMANAGETYPE=ds.Tables[0].Rows[0]["SUBSYSTEMUSERMANAGETYPE"].ToString();
				model.SUBSYSTEMREMARK=ds.Tables[0].Rows[0]["SUBSYSTEMREMARK"].ToString();
				model.SUBSYSIMAGE=ds.Tables[0].Rows[0]["SUBSYSIMAGE"].ToString();
                model.ISDISPLAY = ds.Tables[0].Rows[0]["ISDISPLAY"].ToString();
                model.DIRECTION = ds.Tables[0].Rows[0]["DIRECTION"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
            strSql.Append("select SUBSYSTEMID,SUBSYSTEMNAME,SUBSYSTEMLOGONMETHOD,SUBSYSTEMLOGONURL,SUBSYSTEMCREATEUSERISN,SUBSYSTEMCREATETIME,SUBSYSTEMCHANGETIME,SUBSYSTEMCHANGEUSERISN,SUBSYSTEMSTATE,SUBSYSTEMRUNNINGSTATE,SUBSYSTEMTYPE,SUBSYSTEMUSERMANAGETYPE,SUBSYSTEMREMARK,SUBSYSIMAGE,ISDISPLAY,DIRECTION ");
			strSql.Append(" FROM SUBSYS_INFO ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" WHERE "+strWhere);
			}
            strSql.Append(" ORDER BY SUBSYSTEMID");
			return OracleHelper.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "SUBSYS_INFO";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}

